import unittest
from time import sleep

import ddt
from selenium import webdriver
from selenium.webdriver.common.by import By

from num01_123.csvv import get_CSV


@ddt.ddt
class Test03(unittest.TestCase):

    def setUp(self) -> None:
        self.driver = webdriver.Chrome()
        self.driver.get("http://192.168.46.5:14753/login")
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
    def tearDown(self) -> None:
        self.driver.quit()

    data = get_CSV()
    @ddt.data(*data)
    def test_denglu01(self,li):
        self.driver.find_element(By.ID,"username").send_keys("XTGLY")
        sleep(2)
        self.driver.find_element(By.NAME,"password").send_keys("123456")
        sleep(2)
        self.driver.find_element(By.TAG_NAME,"button").click()
        sleep(2)
        self.driver.find_element(By.LINK_TEXT, "商品分类").click()
        sleep(2)
        self.driver.find_element(By.XPATH, "//*[@id='app']/div/div[2]/section/div/div[2]/div[3]/button").click()
        sleep(2)
        self.driver.find_element(By.CLASS_NAME, "el-input__inner").send_keys(li[0])
        sleep(2)
        self.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[3]/div/button[1]").click()
        sleep(2)
        error_mag = self.driver.find_element(By.CLASS_NAME, "el-form-item__error").text
        try:
            self.assertEqual(error_mag,li[1])
        except AssertionError:
            self.driver.get_screenshot_as_file("D:\\test_accept03.png")

if __name__ == '__main__':
    unittest.main()
